<link rel="stylesheet" href="/css/combo.select.css">
<h3 class="text-danger text-bold text-center">分组、域名、属性、修改，都同步更新到推广模板，请慎重修改！</h3>
@if(auth()->user()->id === 1)
    <div class="form-group">
        <label for="tagUid" class="col-md-3 control-label">所属用户</label>
        <div class="col-md-7">
            <select class="form-control" name="uid" id="tagUid"
                    onchange="$('#username').val($(this).find('option:selected').text());">
                @foreach ($userList as $id=>$name)
                    <option value="{{ $id }}" @if ($id === $uid) selected="selected" @endif>{{ $name }}</option>
                @endforeach
            </select>
            <input type="hidden" id="username" name="username" value="{{ empty($username) ? $userList[1] : $username}}">
        </div>
    </div>
@else
    <input type="hidden" id="uid" name="uid" value="{{auth()->user()->id}}">
    <input type="hidden" id="username" name="username" value="{{auth()->user()->name}}">
@endif

<div class="form-group">
    <label for="tagTitle" class="col-md-3 control-label">分组名称</label>
    <div class="col-md-7">
        <input type="text" class="form-control" name="title" id="tagTitle" value="{{ $title }}"
               @if (empty($template)) onblur="$('#template').val($('#tagTempId').find('option:selected').text())"
               @endif autofocus>
    </div>
</div>

<div class="form-group">
    <label for="tag" class="col-md-3 control-label">分组目录</label>
    <div class="col-md-7">
        <input type="text" class="form-control" name="directory" id="tag" value="{{ $directory ? $directory: '/' }}">
    </div>
</div>
<hr>
{{--
<h2>推广页-设置访问条件限制：</h2>
<div class="form-group" style="">
    <label for="tagTerm" class="col-md-3 control-label">选择条件：</label>
    <div class="col-md-3">
		 <select class="form-control" name="" id="tagTerm"
				onchange="$('#term').val($(this).find('option:selected').val());">
				<option value="0">请选择条件</option>
			@foreach ($terms as $term)
				<option value="{{ $term->id }}" @if ($term->id==$term_id) selected="selected" @endif>{{ $term->name }}</option>
			@endforeach
		</select>
		<input type="hidden" id="term" name="term_id" value="{{$term_id}}">
    </div>
</div>

<hr>
--}}
<h2>设置-分组跳转：</h2>
<div class="form-group" style="overflow:hidden;">
    <label for="tagGoToType" class="col-md-3 control-label">是否跳转</label>
    <div class="col-md-3">
        <select class="form-control" name="go_to_type" id="tagGoToType"
                onchange="$('#go_to_type_title').val($(this).find('option:selected').text());">
            @foreach (config('app.go_to_type') as $key => $name)
                <option value="{{ $key }}" @if ($key === $go_to_type) selected="selected" @endif>{{ $name }}</option>
            @endforeach
        </select>
        <input type="hidden" id="go_to_type_title" name="go_to_type_title"
               value="{{ empty($go_to_type_title) ? config('app.go_to_type')[0] : $go_to_type_title}}">
    </div>
</div>

<div class="form-group @if(!$go_to_type) hide @endif" id="TargetGidArea" style="">
    <label for="target_gid" class="col-md-3 control-label">跳转目标分组</label>
    <div class="col-md-3">
        <select class="form-control" name="" id="target_gid" onchange="$('#target_gid').val($(this).find('option:selected').val());">
            <option value="0">NULL</option>
            @foreach ($groupList as $gid=>$title)
                <option value="{{ $gid }}"
                        @if ($gid === $target_gid) selected="selected" @endif>{{ $title }}</option>
            @endforeach
        </select>
		<input type="hidden"  name="target_gid"
               value="{{ $target_gid }}">
        <input type="hidden" id="target_gname" name="target_gname"
               value="{{ empty($target_gname) ? 'NULL' : $target_gname}}">
    </div>
</div>

<div id="TempateArea" class="@if($go_to_type) hide @endif" >

@foreach($tpls as $tk=>$tpl)
    <div data-id="{{$tk+1}}" id="group_{{$tk+1}}" class="form-group" style="">
        <label for="tagTempId" class="col-md-3 control-label">推广模板{{$tk+1}}</label>
        <div class="col-md-3" id="template_to">
            <select class="form-control" name="" id="tagTempId_{{$tk}}"
                    onchange="$('#template_{{$tk}}').val($(this).find('option:selected').text());$('#tpl_id_{{$tk}}').val($(this).find('option:selected').val());">

                <option value="0">NULL</option>
                @foreach ($templateList as $tplKey=>$tplName)
                    <option value="{{ $tplKey }}"
                            @if ($tplKey == $tpl) selected="selected" @endif>{{ $tplName }}</option>
                @endforeach
            </select>
            <input type="hidden" id="template_{{$tk}}" name="template[]" value="{{$template[$tk]}}">
			<input type="hidden" id="tpl_id_{{$tk}}" name="tpl_id[]" value="{{$tpl}}">
        </div>
		<div class="col-md-3">
			 <select class="form-control" id="term_{{$tk}}" name="" onchange="$('#term{{$tk}}').val($(this).find('option:selected').val());">
					<option value="0">请选择条件</option>
				@foreach ($terms as $mk=>$term)
					<option value="{{ $term->id }}" @if ($term->id==$term_id[$tk]) selected="selected" @endif>{{ $term->name }}</option>
				@endforeach
			</select>
			<input type="hidden" id="term{{$tk}}" name="term_id[]" value="{{$term_id[$tk]}}">
		</div>
		@if($tk==0)
		<div class="col-md-3 "><a href="javascript:;" class="btn btn-success btn-addTemplate"><i class="fa fa-plus-circle"></i> 添加</a></div>
		@else
		<div class="col-md-3 "><a href="javascript:;" class="btn btn-danger btn-delTemplate"><i class="fa fa-times-circle-o"></i> 删除</a></div>
		@endif
	</div>
	@endforeach
	<hr/>
    <div class="form-group" style="">
        <label for="tagShTempId" class="col-md-3 control-label">审核页</label>
        <div class="col-md-3">
            <select class="form-control" name="" id="tagShTempId"
                    onchange="$('#sh_template').val($(this).find('option:selected').text());$('input[name=sh_tpl_id]').val($(this).find('option:selected').val());">

                <option value="0">NULL</option>
                @foreach ($templateList as $tplKey=>$tplName)
                    <option value="{{ $tplKey }}"
                            @if ($tplKey == $sh_tpl_id) selected="selected" @endif>{{ $tplName }}</option>
                @endforeach
            </select>
            <input type="hidden" id="sh_template" name="sh_template" value="{{$sh_template}}">
			<input type="hidden" id="template" name="sh_tpl_id" value="{{$sh_tpl_id}}">
        </div>

        <div class="col-md-3">
			 <select class="form-control" id="sh_term" name="" onchange="$('#sh_term_id').val($(this).find('option:selected').val());">
					<option value="0">请选择条件</option>
				@foreach ($terms as $mk=>$term)
					<option value="{{ $term->id }}" @if ($term->id==$sh_term_id) selected="selected" @endif>{{ $term->name }}</option>
				@endforeach
			</select>
			<input type="hidden" id="sh_term_id" name="sh_term_id" value="{{$sh_term_id}}">
		</div>

    </div>
</div><br style="clear:both;"/>
{{--#################The End################--}}
<hr>
<h2>选择推广微信号<span class="text-danger">*</span>&nbsp; <!--<input class="wechat" type="checkbox" name="wechat_list_all" id="wechat_list_all">--></h2>

            
<div class="form-group" style="overflow:hidden;">

    <div class="col-md-12">
        <label for="page-url" class="col-md-3 control-label">
            <select class="form-control col-md-5" id="" onchange="showWG(this.value)">
                <option value="0">全部分组</option>
              @foreach($wechatgroup as $v)
                <option value="{{$v['id']}}">{{$v['name']}}</option>
               @endforeach
            </select>
        </label>
        <div class="col-md-7" id="wechatListAll">
            @foreach($wechatgroup as $v)
                <div id="fieldset_{{$v['id']}}" class="wg" style="border:1px solid #eee;margin-bottom:5px;padding:5px;border-radius:5px;">

                    <label class="css-input css-checkbox-sm css-checkbox css-checkbox-success push-8-r">
					<input onchange="setW('w_{{$v['id']}}')" type="checkbox" id="w_{{$v['id']}}" ><span></span>{{$v['name']}}
                    </label>
						<hr style="margin:0px"/>
					@foreach($wechats as $wechat) 
                        @if($wechat['group']==$v['id']&&$wechat['status']==1)
						<label class="css-input css-checkbox-sm css-checkbox css-checkbox-success push-8-r">
                        <input onchange="wechat()" data-id="{{$wechat['id']}}" class="wechat w_{{$v['id']}}" type="checkbox" name="wechat_list[]" value="{{$wechat['wx_num']}}"@foreach(explode(',',$wechat_list) as $keyWx => $objWx)@if($wechat['wx_num'] == $objWx) checked @endif @endforeach><span></span>{{$wechat['wx_num']}}&nbsp;&nbsp;&nbsp;
                        </label>
						@endif
                    @endforeach
					<hr style="margin:0px"/>
					@foreach($wechats as $wechat) 
                        @if($wechat['group']==$v['id']&&$wechat['status']!=1)
						<label class="css-input css-checkbox-sm css-checkbox css-checkbox-success push-8-r">
							<s>{{$wechat['wx_num']}}</s>&nbsp;&nbsp;&nbsp;
                        </label>
						@endif
                    @endforeach
                </div>
            @endforeach
            <input type="hidden" name="wechat_list" value="{{$wechat_list}}"/>
			<input type="hidden" name="wechat_ids" value="{{$wechat_ids}}"/>
            {{--@foreach($wechats as $key => $obj)

                    <input class="wechat" type="checkbox" name="wechat_list[]" value="{{$obj->wx_num}}"
                           @foreach(explode(',',$wechat_list) as $keyWx => $objWx)
                           @if($obj->wx_num == $objWx) checked @endif
                            @endforeach
                    ><span ></span>
                    <span title="随机值：{{$obj->max_rand}} 上线时间：{{$obj->online_time}} 下线时间：{{$obj->offline_time}}">
                        {{$obj->wx_num}}——<b  class="text-danger">{{$obj->wx_nike}}</b>
                    </span>

            @endforeach--}}

        </div>
<a href="/admin/wechat/create">添加微信</a>
    </div>
</div>

<hr>
@if(!empty($template))
    <div class="form-group" style="overflow:hidden;">
        <label for="unCover" class="col-md-3 control-label">是否覆盖所在域名对应配置</label>
        <div class="col-md-7 radio">
            <label>
                <input type="radio" name="cover" id="unCover" value="unCover"> 不覆盖
            </label>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>
                <input type="radio" name="cover" id="cover" value="cover"  checked="checked"> 覆盖
            </label>
        </div>
    </div>
@endif

{{--
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                       <h2>推广页-设置访问条件限制：</h2>
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="deleteForm" method="POST" action="/admin/group">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="POST">
						
<div class="form-group">
    <div class="col-md-12">
        <label for="station-type" class="col-md-3 control-label">站点类型<span
                    class="text-danger">*</span></label>
        <div class="col-md-7">
            <select class="form-control" id="station_type" name="station_type">
                @foreach(Config::get('app.station_type') as $key => $obj)
                    <option value="{{$key}}" @if($station_type == $key) selected @endif>{{$obj}}</option>
                @endforeach
            </select>
        </div>
    </div>
</div>
<div class="form-group">
    <div class="col-md-12">
        <label for="station-type" class="col-md-3 control-label">设备选择<span
                    class="text-danger">&nbsp;</span></label>
        <div class="col-md-7">
            @foreach(Config::get('app.device_type') as $key => $obj)
                <label class="css-input css-radio css-radio-success push-10-r">
                    <input type="radio" name="device_type" value="{{$key}}"
                           @if($device_type == $key) checked @endif><span></span> {{$obj}}
                </label>
            @endforeach


        </div>
    </div>
</div>
<div class="form-group">
    <div class="col-md-12">
        <label for="page-url" class="col-md-3 control-label">投放区域过滤<span
                    class="text-danger">*</span></label>
        <div class="col-md-7">
            <label class="css-input css-radio css-radio-success push-10-r">
                <input type="radio" name="area_config" value="0" @if($area_config == 0) checked="" @endif><span></span>
                关闭
            </label>

            <label class="css-input css-radio css-radio-success push-10-r">
                <input type="radio" name="area_config" value="2" @if($area_config == 2) checked="" @endif><span></span>
                选择不投放地区
            </label>

        </div>

    </div>
</div>
<div id="area-display" @if($area_config == 0)  style="display: none" @endif>
    <div class="form-group">
        <div class="col-md-12">
            <label class="col-md-3 control-label">不投放地区地区选择<span
                        class="text-danger">&nbsp;</span></label>
            <div class="col-md-7" id="select-area">

            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-12">
            <label class="col-md-3 control-label">已选不投放地区<span
                        class="text-danger">&nbsp;</span></label>
            <div class="col-md-7" style="white-space:normal; " id="selected-area">

            </div>
        </div>
    </div>


</div>
<div class="form-group">
    <div class="col-md-12">
        <label for="page-url" class="col-md-3 control-label">UserAgent限制<span
                    class="text-danger">*</span></label>
        <div class="col-md-7">
            @foreach(Config::get('app.allow_channel') as $key => $obj)
                <label class="css-input css-checkbox-sm css-checkbox css-checkbox-success push-10-r">
                    <input class="channel" type="checkbox" name="allow{{$key}}" value="{{$key}}"
                           @foreach(explode(',',$channel) as $keyChannel => $objChannel)
                           @if($key == $objChannel) checked @endif
                            @endforeach
                    ><span></span> 允许{{$obj}}中访问
                </label>
            @endforeach
            <input id="channelValue" class="col-md-7" name="channel" value="{{$channel}}"
                   placeholder="格式:QQ,MicroMessenger,NewsArticle,">
        </div>

    </div>
</div>
<div class="form-group">
	<div class="col-md-12">
		<label class="col-md-3 control-label">来源限制<span
					class="text-danger">&nbsp;</span></label>
		<div class="col-md-7" style="white-space:normal; " id="ips">
			 <input id="source" class="col-md-7" name="source" value="{{$source}}"
                   placeholder="格式:baidu.com,qq.com">
		</div>

	</div>
</div>
<div class="form-group">
	<div class="col-md-12">
		<label class="col-md-3 control-label">IP限制<span
					class="text-danger">&nbsp;</span></label>
		<div class="col-md-7" style="white-space:normal; " id="ips">
			<textarea class="col-md-7" name="ips" placeholder="格式:192*118*1*1,192*118*1*255">{{$ips}}</textarea>
		</div>

	</div>
</div>
<div class="form-group">
        <div class="col-md-12">
            <label class="col-md-3 control-label">投放时间<span
                        class="text-danger">&nbsp;</span></label>
            <div class="col-md-7" style="" id="delivery_time">

				<input type="hidden" class='dv col-md-6' name="delivery_time" value='{{$delivery_time}}' readonly="readonly">&nbsp;&nbsp;<label class="css-input css-checkbox-sm css-checkbox css-checkbox-success push-8-r"><input onchange="setDt()" type="checkbox" id="dt_all" @if($delivery_time=='0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23') checked @endif><span></span>全选</label>

				<div style="clear:both;"></div>
				<div >
				@foreach($delivery_times as $dt)
				<label class="css-input css-checkbox-sm css-checkbox css-checkbox-success push-8-r">
						<input class="dt" onchange="delivery({{$dt}})" type="checkbox" value='{{$dt}}' @if(isset($delivery_value[$dt]))checked @endif><span></span>{{$dt}}:00~{{$dt+1}}:00 @if($dt<10) &nbsp;&nbsp;@endif &nbsp;
					</label>
					@if($dt==11)<br/>@endif
				@endforeach
				</div>
            </div>
        </div>
    </div>
</div>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>--}}
@section('js')
    <link rel="stylesheet" href="//as.linwenfa.com/long/css/oneui.css">
    <script src="//as.linwenfa.com/long/js/area.js"></script>

	<script src="/js/jquery.combo.select.js"></script>
    <script type="text/javascript">
		var id = 0+1;
		@foreach($tpls as $tk=>$tpl)
			$('#tagTempId_{{$tk}}').comboSelect();
			$('#term_{{$tk}}').comboSelect();
			id = 1+parseInt({{$tk}});
		@endforeach
		$('#sh_term').comboSelect();
		$('#target_gid').comboSelect();
		$('#tagTerm').comboSelect();
		$('#tagShTempId').comboSelect();
        var areas = [{!! $area_list !!}];
        $.areaSelect('#select-area', '#selected-area',areas);
        $(document).ready(function () {
            $('.channel').click(function () {
                var $channelValue = $("#channelValue").val();
                var $newValue = $(this).val() + ',';
                if ($(this).get(0).checked) {
                    $channelValue = $channelValue.replace($newValue, '');
                    $("#channelValue").val($channelValue + $newValue);
                } else {
                    $channelValue = $channelValue.replace($newValue, '');
                    $("#channelValue").val($channelValue);
                }
            });


            $('#station-type').change(function () {
                if ($(this).val() == 2) {
                    $('#weixinInfo').show();
                    $('input[name="allowweixin"]').prop('checked', true);
                } else {
                    $('#weixinInfo').hide();
                    $('input[name="allowweixin"]').prop('checked', false);
                }
            })
            $('#station-type').trigger('change');
			//var id = Math.floor(Math.random()*10000);
			
			$(".btn-addTemplate").click(function(){
				++id;
				var html = '<div data-id="'+(id)+'" id="group_'+id+'" class="form-group" style=""><label for="tagTempId" class="col-md-3 control-label">推广模板'+id+'</label><div class="col-md-3" id="template_to">'
							+'<select class="form-control" name="" id="tagTempId_'+id+'" onchange="$(\'#template_'+id+'\').val($(this).find(\'option:selected\').text());$(\'#tpl_id_'+id+'\').val($(this).find(\'option:selected\').val());">'
							+'<option value="0">NULL</option>'
							@foreach ($templateList as $tplKey=>$tplName)
								+'<option value="{{ $tplKey }}" @if ($tplKey === $tpl_id) selected="selected" @endif>{{ $tplName }}</option>'
							@endforeach
							+'</select>'
							+'<input type="hidden" id="template_'+id+'" name="template[]" value="">'
							+'<input type="hidden" id="tpl_id_'+id+'" name="tpl_id[]" value="">'
							+'</div>'
							+'<div class="col-md-3">'
							+'<select class="form-control" id="term_'+id+'" name="" onchange="$(\'#term'+id+'\').val($(this).find(\'option:selected\').val());">'
							+'<option value="0">请选择条件</option>'
							@foreach ($terms as $mk=>$term)
								+'<option value="{{ $term->id }}" >{{ $term->name }}</option>'
							@endforeach
							+'</select>'
							+'<input type="hidden" id="term'+id+'" name="term_id[]" value="0">'
							+'</div><div class="col-md-3 "><a href="javascript:;" class="btn btn-danger btn-delTemplate"><i class="fa fa-times-circle-o"></i> 删除</a></div></div></div>';
				var gid = id-1;
				$("#group_"+gid).after(html);
				$('#tagTempId_'+id).comboSelect();
				$('#term_'+id).comboSelect();
			});
			
			$("#TempateArea").delegate('.btn-delTemplate', 'click', function () { //删除节点
				var this_id = parseInt($(this).parent().parent().data('id'));
				$(this).parent().parent().remove();
				if(this_id==id){ 
					for(var i = this_id;i>0;i--){ 
						if($("#group_"+i).length>0){
							id = i;
							break;
						}
					}
				}
			});
        })
       /*  $('input[name="area_config"]').click(function () {
            if ($(this).val() != 0) {
                $('#area-display').show();
            } else {
                $('#area-display').css({'display': 'none'});
            }
        }); */

        //跳转分组
        $("#tagTargetGid").change(function () {
            $('#target_gname').val($(this).find('option:selected').text());
        });

        //是否跳转
        $("#tagGoToType").change(function () {
            if ($(this).val() == 0) {
                $("#TargetGidArea").removeClass('hide').hide();
                $("#tagTargetGid").val(0);
                $("#TempateArea").removeClass('hide').fadeIn('slow');
            } else {
                $("#TargetGidArea").removeClass('hide').fadeIn('slow');
                $("#TempateArea").removeClass('hide').hide();
                $("#tagTempId").val(0);
                $("#tagShTempId").val(0);
            }
        });

    //选中微信
     function wechat(){
        var str = '';var ids = '';
        $(".wechat:checked").each(function(){
           str+=this.value+',';
		    ids+=$(this).data('id')+',';
        });
        str=str.substring(0,str.length-1);
		ids=ids.substring(0,ids.length-1);
        $('input[name=wechat_list]').val(str);
		 $('input[name=wechat_ids]').val(ids);
    }

    //选中微信分组
    function setW(c){
        $("."+c).prop("checked",$("#"+c).is(":checked"));
        wechat();
    }

    //选择显示微信分组
    function showWG(c){
        if(c==0){
            $(".wg").slideDown();
        }else{
            $(".wg").slideUp();
            $("#fieldset_"+c).slideDown();
        }
    }
	
	//选中时间
	function delivery(value){ 
		var str = '';
		$(".dt:checked").each(function(){
		   str+=this.value+',';
		});
		str=str.substring(0,str.length-1);
		$('.dv').val(str);
	}
	//全选时间
	function setDt(){
		$(".dt").prop("checked",$("#dt_all").is(":checked"));
		delivery(0);
	}
    </script>
    <script src="//as.linwenfa.com/long/js/layer.js"></script>
    <script src="//as.linwenfa.com/long/js/station.editor.js"></script>
@endsection
